package com.foreknow.eldclient.dao;

import com.foreknow.eldclient.po.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserMapper {
    /**
     * 登录验证
     * 根据用户ID和用户密码查询
     * @param userId
     * @param password
     * @return
     * @throws Exception
     */
    @Select(" select * from user where userId=#{userId} and password=#{password}")
    public User getUserByIdByPass(@Param("userId") String userId, @Param("password") String password) throws Exception;

    /**
     * 查找该用户的注册数量
     * @param userId
     * @return
     * @throws Exception
     */
    @Select("select count(*) from user where userId=#{userId}")
    public int getUserById(String userId) throws Exception;

    /**
     * 注册
     * 向用户表中添加一条记录
     * @param user
     * @return
     * @throws Exception
     */
    @Insert("insert into user(userId,password,userName,userSex,userImg) values(#{userId},#{password},#{userName},#{userSex},#{userImg})")
    public int saveUser(User user) throws Exception;

    @Select("select userImg from user where userId=#{userId}")
    String getUserImg(String userId);

    @Update("update user set userName=#{userName},userSex=#{userSex},userImg=#{userImg} where userId=#{userId}")
    int updateUser(User user);
}
